/*
Copyright (c) 2006 - 2008  Universitaet Osnabrueck, virtUOS
Authors: Markus Ketterl, Johannes Emden, Nils Schuhmacher, Andreas Rickling

This file is part of virtPresenter.

virtPresenter is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

virtPresenter is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with virtPresenter.  If not, see <http://www.gnu.org/licenses/>.
*/

package virtPresenter.commands
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.cairngorm.control.CairngormEventDispatcher;
	
	import mx.core.Application;
	
	import virtPresenter.event.CairngormErrorEvent;
	import virtPresenter.event.GoToLectureEvent;
	import virtPresenter.event.ThumbnailSelectedEvent;
	import virtPresenter.model.TimeStep;
	import virtPresenter.model.virtPresenterLocator;
	import mx.core.Application;
	
	/**
	 * Command handles when the index of a selected thumbnail has changed.
	 * */
	public class ChangeThumbnailIndex implements ICommand {			
		
		/**
		 * Handler for ThumbnailSelectedEvent.
		 * If the user clicks on a Thumbnail in the SlideBrowser view this method declares
		 * how to react on this.
		 * */
		public function execute( event : CairngormEvent ): void
			{				
				var model : virtPresenterLocator = virtPresenterLocator.getInstance();
				
				if(model.netStream!=null){
					var ThumbnailChanged : ThumbnailSelectedEvent =ThumbnailSelectedEvent( event );
					model.selectedThumbnailIndex=ThumbnailChanged.selected;	
					
					//trace("ChangeThumbnailIndex. Time of selected item: "+model.slideBrowserView.ThumbnailTileList.selectedItem.getTime());
					
					var time:int=model.slideBrowserView.ThumbnailTileList.selectedItem.getTime();						
					
					model.views.selectedChild=model.defaultView;
										
					//TO-DO: If we had the big video view previously reset the view with big video
					model.viewComboBox.selectedIndex=0;					
					
					CairngormEventDispatcher.getInstance().dispatchEvent(new GoToLectureEvent(model.lectureFolder,time));					
									
				}
				
				if(model.netStream==null)
				{	
					var err:TypeError=new TypeError("Currently the Videoserver is down for maintenance.");
					CairngormEventDispatcher.getInstance().dispatchEvent(new CairngormErrorEvent(err,"Please contact mketterl@uos.de"));
				}
				
				
		}
	
		
	}
	
	
}